home *** CD-ROM | disk | FTP | other *** search
- Path: news.ov.com!news
- From: glenn@ov.com (Fletcher.Glenn@ov.com)
- Newsgroups: comp.lang.c
- Subject: Re: Q: Terminating program at EOF
- Date: 9 Jan 1996 21:45:29 GMT
- Organization: OpenVision
- Message-ID: <4cunlp$flp@spanky.pls.ov.com>
- References: <4cn66j$5r0@fnpx20.fnal.gov>
- Reply-To: glenn@ov.com
- NNTP-Posting-Host: foghorn.pls.ov.com
-
- In article 5r0@fnpx20.fnal.gov, sfield@fnpx20.fnal.gov (Stephen Field) writes:
- >Hi,
- >
- >I'm writing a program that looks at poorly formatted text files and reformats
- >them to a user-specified line length. The input text file has a blank line
- >between paragraphs and I would like the newly formatted file to also have blank
- >lines between paragraphs.
- >
- >I've written a program that does the job, but it doesn't stop when it reaches
- >the end of the file. The program will write out the reformatted file, but it
- >appends a lot of "extra" characters to the end of the file and only stops when
- >I break out of it.
- >
- >I have tried this program on many files and it behaves the same. The program
- >is included below and I've got it running on an SGI running IRIX.
- >
- >Any help appreciated.
- >
- >Steve
- >
- >===================================================
- >/* This program reformats a file that is input by the user to not exceed
- > a number of columns that is also input and outputs the reformatted file
- > to a file also given by the user at runtime. Lines are broken at spaces. */
- >#include <stdio.h>
- >#define MAX_WORD_LENGTH 80 /* max length of word in input */
- >
- >main()
- >{
- > int line_length, /* max length of line in output */
- > curr_line_length = 0, /* # of chars printed so far in curr line */
- > word_length; /* length of current word */
- > char word[ MAX_WORD_LENGTH+1];/* buffer to read word +1 for terminating
- > '\0' */
- > char c_old=' ',c_new=' '; /* check for newlines with chars */
- >
- [snipped irrelevant code]
-
- Your problem is that fgetc() returns an int, and c_new is a char. It is
- not possible to test a char for EOF as EOF is bigger than a char.
-
- Fletcher.Glenn@ov.com
-
- >/* while((c_new=fgetc(fptr_read))!=EOF){ */ /* old method for removing EOF bug */
- > while(c_new!=EOF){ /* new method, still doesn't work */
- > c_new=fgetc(fptr_read);
- [snipped more irrelevant code]
-
-